<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Dotnet2-web 后台管理系统</title>
<!--[if lt IE 9]>
<script src="js/html5.js"></script>
<![endif]-->
<%@ include file="/jsp/common/commonJs.jsp"%>
</head>
<body>
<!--header-->
<%@ include file="/jsp/top.jsp"%>
<!--header-->

<!--aside nav-->
<%@ include file="/jsp/left.jsp"%>
<!--aside nav  -->
<div class="rt_content">
	<section class="rt_wrap content mCustomScrollbar" style="margin-top:10px;">
		  <div class="page_title">
	       	 <h2 class="fl">产品模板在线编辑</h2>
	      </div>
	      <input type="hidden" id="id" value="${template.id}" />
	      <input type="hidden" id="productId" value="${productId}" />
	      <input type="hidden" id="productName" value="${productName}" />
	      <script id="editor" type="text/plain" style="width:1024px;height:500px;overflow:scroll">${template.temHtml}</script>
	      <div class="btm_btn">
	        <input type="button" value="提交" onclick="sub()" class="input_btn trueBtn"/>
	        <input type="button" value="重置" onclick="clearContent()" class="input_btn falseBtn"/>
	      </div>
	</section>
 </div>
<!-- 实例化编辑器 -->
<script type="text/javascript">
	var ue = UE.getEditor('editor',{
	 	toolbars: [
	 	           ['preview']
		       ]
		       ,focus :true
		       ,enableAutoSave :false
		       ,elementPathEnabled:false
		       ,initialFrameHeight:500
		       ,initialFrameWidth:1024
		       ,wordCount:false  //关闭统计字数
		       ,autoHeightEnabled:false
		       //
	 });
    function sub(){
    	var html=ue.getContent();
    	var content=ue.getContentTxt();
    	if(!ue.hasContents()){
    		alert("请先填写内容!");
    		return;
    	}
    	var productId=$("#productId").val();
    	$.ajax({
            type: "post",
            url: "${path}/template/template.do",
            data: {temHtml:html, productId:productId ,id : $("#id").val() ,temContent:content ,productName : $("#productName").val()},
            dataType: "json",
            success: function(data){
				if(data.status){
					window.location.href="${path}/template/productList.do";
				}else{
					alert("请求服务器错误,请稍微再试!");
				}
        	}
    	});
    	
    }
    
    function clearContent(){
    	//重置内容
    	ue.setContent("");
    }
    
    ue.ready(function() {
    //设置编辑器的内容  默认hello
    var productId=$("#productId").val();
    var html="var productId="+productId+";";
    var id=$("#id").val();
	    if(''==id){
	    	ue.execCommand("insertHTML",html);
	    }
    });
</script>
</body>
</html>
